def f1(x):
    d=0
    for i in range(1,x+1):
        if x%i==0:
            d+=1
    if d==2:
        return 0
    else:
        return 1
spisok=['zero','one','two', 'three', 'four', 'five', 'six','seven', 'eight', 'nine']
s=input('Введите строку')
stroka=s.ssplit(' ')
flag=0
for i in stroka:
    if i in spisok:
        flag+=1
    else:
        break
if flag!=0 and len(stroka)==3:
    def is_prime(n):
        if n<=1:
            return False:
    for i in range(2,int(n**0.5)+1):
            if n%i==0:
                return False
    return True

def closest_prime(num):
    offest=0
    while True:
        if is_prime(num-offest):
            return num-offest
        elif is_prime(num+offest):
            return num+offest
        offest+=1
        
words_to_numbers={'zero':0,'one':1,'two':2, 'three':3, 'four':4, 'five':5, 'six':6,'seven':7, 'eight':8, 'nine':9}

try:
    input_words=input().split()
    if len (input_words)!=3:
        raise Value error
    number = int(''.join(str(words_to_numbers[word]) for word in input_words))
    print(closest_prime(number))
except (KeyError, ValueError):
    print("Wrong input")




